home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Control Common / CBaseBindStatusCallback.cpp next >
Text File  |  1996-12-30  |  6KB  |  239 lines

  1. // =================================================================================
  2. //
  3. //    CBaseBindStatusCallback.cpp        ©1996 Microsoft Corporation All rights reserved.
  4. //
  5. // =================================================================================
  6.  
  7. #include "ocheaders.h"
  8. #include "CBaseBindStatusCallback.h"
  9. #include "urlmonsupport.h"
  10.  
  11.  
  12. static FORMATETC FileFormatEtc = {
  13.     CF_NULL,
  14.     NULL,
  15.     DVASPECT_CONTENT,
  16.     -1,
  17.     TYMED_FSP
  18. };
  19.  
  20.  
  21. #pragma mark === CBaseBindStatusCallback::Construction & Destruction ===
  22.  
  23. //
  24. //  CBaseBindStatusCallback::CBindStatusCallback
  25. //
  26. //  Constructor
  27. //
  28. CBaseBindStatusCallback::CBaseBindStatusCallback(void)
  29. {
  30. }
  31.  
  32.  
  33. //
  34. //  CBaseBindStatusCallback::~CBaseBindStatusCallback
  35. //
  36. //  Destructor
  37. //
  38. CBaseBindStatusCallback::~CBaseBindStatusCallback(void)
  39. {
  40. }
  41.  
  42.  
  43. #pragma mark === CBaseBindStatusCallback::IUnknown ===
  44.  
  45. //
  46. //  CBaseBindStatusCallback::IUnknown::QueryInterface
  47. //
  48. //  Returns a pointer to the specified interface on a component to which a
  49. //  client currently holds an interface pointer.
  50. //
  51. STDMETHODIMP
  52. CBaseBindStatusCallback::QueryInterface(REFIID inRefID, void** outObj)
  53. {
  54.     ErrorCode    Result = CBaseCOM::QueryInterface(inRefID, outObj);
  55.  
  56.     if ( Result == E_NOINTERFACE )
  57.     {
  58.           void* pv = nil;
  59.            
  60.         if ( inRefID == IID_IBindStatusCallback )
  61.             pv = (void*)(IBindStatusCallback*) this;
  62.             
  63.         *outObj = pv;
  64.     
  65.         // if we got an interface, ref it and return ok
  66.         if ( pv )
  67.         {
  68.                 ((IUnknown*) pv)->AddRef();
  69.             Result =  S_OK;
  70.         }
  71.     }
  72.     
  73.     return Result;
  74. }
  75.  
  76.  
  77.  
  78.  
  79. #pragma mark === CBaseBindStatusCallback::IBindStatusCallback ===
  80.  
  81. //=--------------------------------------------------------------------------=
  82. //  CBaseBindStatusCallback::IBindStatusCallback::OnStartBinding
  83. //=--------------------------------------------------------------------------=
  84. //
  85. STDMETHODIMP
  86. CBaseBindStatusCallback::OnStartBinding(Uint32 BSCOption, IBinding* Binding)
  87. {
  88. #pragma unused (BSCOption)
  89.     mibP = Binding;
  90.     mibP->AddRef();
  91.     mTotalStreamLen = 0;
  92.  
  93.     return S_OK;
  94. }
  95.  
  96.  
  97. //=--------------------------------------------------------------------------=
  98. //  CBaseBindStatusCallback::IBindStatusCallback::GetPriority
  99. //=--------------------------------------------------------------------------=
  100. //
  101. STDMETHODIMP
  102. CBaseBindStatusCallback::GetPriority(Int32 *Priority)
  103. {
  104.     *Priority = 0;
  105.     return S_OK;
  106. }
  107.  
  108.  
  109. //=--------------------------------------------------------------------------=
  110. //  CBaseBindStatusCallback::IBindStatusCallback::OnLowResource
  111. //=--------------------------------------------------------------------------=
  112. //
  113. STDMETHODIMP
  114. CBaseBindStatusCallback::OnLowResource(Uint32 reserved)
  115. {
  116. #pragma unused (reserved)
  117.     return S_OK;
  118. }
  119.  
  120.  
  121. //=--------------------------------------------------------------------------=
  122. //  CBaseBindStatusCallback::IBindStatusCallback::OnProgress
  123. //=--------------------------------------------------------------------------=
  124. //
  125. STDMETHODIMP
  126. CBaseBindStatusCallback::OnProgress(Uint32 Progress, Uint32 ProgressMax, Uint32 StatusCode, const Char8* StatusText)
  127. {
  128. #pragma unused (Progress, ProgressMax, StatusCode, StatusText)
  129.     return S_OK;
  130. }
  131.  
  132.  
  133. //=--------------------------------------------------------------------------=
  134. //  CBaseBindStatusCallback::IBindStatusCallback::OnStopBinding
  135. //=--------------------------------------------------------------------------=
  136. //
  137. STDMETHODIMP
  138. CBaseBindStatusCallback::OnStopBinding(ErrorCode ErrCode, const char* Error)
  139. {
  140. #pragma unused (ErrCode, Error)
  141.     if (mibP != NULL)
  142.         mibP->Release();
  143.     mibP = NULL;
  144.     
  145.     return S_OK;
  146. }
  147.  
  148.  
  149.  
  150. //=--------------------------------------------------------------------------=
  151. //  CBaseBindStatusCallback::IBindStatusCallback::GetBindInfo
  152. //=--------------------------------------------------------------------------=
  153. //
  154. STDMETHODIMP
  155. CBaseBindStatusCallback::GetBindInfo(Uint32* BINDF, BINDINFO *BindInfo)
  156. {
  157.     *BINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE;
  158.     BindInfo->dwBindVerb = BINDVERB_GET;
  159.     return S_OK;
  160. }
  161.  
  162.  
  163. //=--------------------------------------------------------------------------=
  164. //  CBaseBindStatusCallback::IBindStatusCallback::OnDataAvailable
  165. //=--------------------------------------------------------------------------=
  166. //
  167. STDMETHODIMP
  168. CBaseBindStatusCallback::OnDataAvailable(Uint32 BSCF, Uint32 Size, FORMATETC* FormatEtc, STGMEDIUM* StgMedium)
  169. {
  170. #pragma unused (BSCF, Size, FormatEtc, StgMedium)
  171.     mDataSize = BSCF == BSCF_LASTDATANOTIFICATION ? 0 : Size;
  172.     mTotalStreamLen += mDataSize;
  173.  
  174.     return S_OK;
  175. }
  176.  
  177.  
  178. //=--------------------------------------------------------------------------=
  179. //  CBaseBindStatusCallback::IBindStatusCallback::OnObjectAvailable
  180. //=--------------------------------------------------------------------------=
  181. //
  182. STDMETHODIMP
  183. CBaseBindStatusCallback::OnObjectAvailable(REFIID RefID, IUnknown* Unknown)
  184. {
  185. #pragma unused (RefID, Unknown)
  186.     return S_OK;
  187. }
  188.  
  189.  
  190. #pragma mark === CBaseBindStatusCallback::Protected Methods ===
  191.  
  192. //=--------------------------------------------------------------------------=
  193. //  CBaseBindStatusCallback::OpenStream
  194. //=--------------------------------------------------------------------------=
  195. //
  196. ErrorCode
  197. CBaseBindStatusCallback::OpenStream(IContainerSite* inContainerSiteP, LPOLESTR URLString, Boolean BindFile)
  198. {
  199.     ErrorCode        Result = E_FAIL;
  200. #pragma unused(BindFile)
  201.  
  202.     LPBINDHOST            BindSiteP;
  203.     LPENUMFORMATETC        pEnum = NULL;
  204.     LPMONIKER            URLMoniker = NULL;
  205.     LPBINDCTX            BindContext = NULL;
  206.  
  207.     inContainerSiteP->QueryInterface(IID_IBindHost, (LPVOID *) &BindSiteP);
  208.  
  209.     if (BindSiteP)
  210.     {
  211.         Result = BindSiteP->CreateMoniker((LPOLESTR)URLString, NULL, &URLMoniker, 0);
  212.         if(SUCCEEDED(Result) && URLMoniker)
  213.         {
  214.             void*        Dummy;
  215.  
  216.             // if BindFile, register enumerator so we get a file
  217.             if(BindFile)
  218.             {
  219.                 Result = CreateBindCtx( 0, &BindContext);
  220.                 if(SUCCEEDED(Result))
  221.                     Result = CreateFormatEnumerator(1, &FileFormatEtc, &pEnum);
  222.                 if(SUCCEEDED(Result))
  223.                     RegisterFormatEnumerator(BindContext, pEnum, 0);
  224.             }
  225.             Result = BindSiteP->MonikerBindToStorage(URLMoniker, BindContext, 
  226.                     (IBindStatusCallback*)this, IID_IStream, &Dummy);
  227.             if(Result == E_PENDING)
  228.                 Result = S_OK;
  229.             if(BindContext)
  230.                 BindContext->Release();
  231.             if(pEnum)
  232.                 pEnum->Release();
  233.             URLMoniker->Release();
  234.         }
  235.     }
  236.  
  237.     return Result;
  238. }
  239.